package com.vma.jifu.backsys.controller;

import com.jfinal.core.Controller;
import com.sun.net.httpserver.HttpsServer;
import com.vma.jifu.bizModel.model.Staff;
import com.vma.tools.ReturnsUtil;

import java.util.Date;

/**
 * Created by kitabi on 2017/6/16.
 */
public class IndexController extends BaseController {


    public void index(){
        String Session = getSessionAttr("staffId");
        if(Session != null && !"".equals(Session)){

            Staff staff = Staff.dao.findById(Session);


            setAttr("staffCode",staff.getStaffCode());

            setSessionAttr("LOGIN_USER_INFO",staff);

            render("/newshop/index/index.jsp");
        }else {

            renderVelocity("/newshop/login/index.html");
        }

    }

    public void toLogin(){

        String Session = getSessionAttr("staffId");
        if(Session != null && !"".equals(Session)){


            Staff staff = Staff.dao.findById(Session);

            staff.setLoginDate(new Date()).update();

            setSessionAttr("LOGIN_USER_INFO",staff);


            setAttr("staffCode",staff.getStaffCode());
            render("/newshop/index/index.jsp");
        }else {

            renderVelocity("/newshop/login/index.html");
        }
    }

    public void loginOut(){
        String Session = getSessionAttr("staffId");

        removeSessionAttr("staffId");
        removeSessionAttr("LOGIN_USER_INFO");


            renderVelocity("/newshop/login/index.html");

    }


    public void getStaff(){

        Staff staff = getSessionAttr("LOGIN_USER_INFO");

        renderJson(ReturnsUtil.returnSuccess(staff));

    }

}
